package com.weseal.dry.service.impl;

import com.weseal.dry.service.BaseService;
import common.data.BaseDomain;
import common.query.AbstractPageQuery;
import common.response.PageResponseResult;
import common.utils.BaseRepository;

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;

/**
 * @author weseal
 * @title
 * @description
 * @usage
 * @copyright Copyright 2014  rrmj Corporation. All rights reserved.
 * @company 上海众多美网络科技有限公司
 * @create 2018/4/20
 */
public class BaseServiceImpl<T extends BaseDomain, V, ID extends Serializable> implements BaseService<T, V, ID> {

	protected static

	private BaseRepository<T, ID> baseRepository;
	private V view;

	public BaseServiceImpl() {

	}

	@Override
	public PageResponseResult<V> pageQuery(AbstractPageQuery query) {
		PageResponseResult pageResponseResult = new PageResponseResult();
		int skip = query.getSkip(), limit = query.getLimit();
		List<T> domainList = baseRepository.queryPage(query.convertPageQuery().skip(skip).limit(limit));
		long count = baseRepository.count(query.convertPageQuery());

		return pageResponseResult;
	}

	@Override
	public <S extends T> V insert(S entity) {
		return null;
	}

	@Override
	public <S extends T> List<V> insert(Iterable<S> entities) {
		return null;
	}

	@Override
	public V findById(ID id) {
		return null;
	}

	@Override
	public boolean existsById(ID id) {
		return false;
	}

	@Override
	public void deleteById(ID id) {

	}

	@Override
	public void update(T id) {

	}


	private void init() {
		try {
			Class<V> cla = (Class<V>) ((ParameterizedType) this.getClass().getGenericSuperclass()).getActualTypeArguments()[1];
			view = cla.newInstance();
		} catch (Exception e) {

		}
	}
}
